<?php
namespace app\index\controller;
use think\Controller;
use think\Db;

class FrValuation extends Controller
{

	public function index(){
        $adcode  = input('get.adCode');
        if($adcode){
            $data = Db::query("select r.*,z.* from xm_region as r left join fr_zone as z on r.region_id = z.city_id where r.region_code = ".$adcode);
            if(!$data){
                $data = Db::query("select r.*,z.* from xm_region as r left join fr_zone as z on r.parent_id = z.city_id where r.region_code = ".$adcode);
            }
            if(!$data){
                $city_id = $data ? $data['city_id'] : 133 ;//如果APP端没有获取adcode 就默认合肥
                $data = Db::table('fr_zone')->where('city_id',$city_id)->find();
            }
        }
        if(input('get.region_id')){
            $data = Db::table('fr_zone')->where('city_id',input('get.region_id'))->find();
        }
        $listPricePc = json_decode($data['price1'],true);
        $listPriceNo = json_decode($data['price2'],true);
        $priceList = $info = [];
        foreach ($listPricePc['mile'] as $key=>$item) {
            $info = explode('-',$item['key']);
            $priceList[$key]['mileage'] = ($info[0]/1000).'-'.($info[1]/1000).'KM';
            $priceList[$key]['moneyOne'] =  $item['value']/100;
            $priceList[$key]['moneyTwo'] =  $listPriceNo['mile'][$key]['value']/100;
        }
        $this->assign('priceList',$priceList);
        $list = Db::table('fr_zone')->where('is_use',1)->order('city_id asc')->select();
        $this->assign('list',$list);
        $this->assign('data',$data);
		return $this->fetch();

	}
}
